package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import lombok.Getter;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author: yingjf
 * @date: 2022/8/11 16:47
 * @description: 竞争对手分析
 */
@Getter
public enum  CompetitorAnalysisEnum {
    //基本信息
    BASE_INFO("other_1", "enum.competitorAnalysis.attrName.base_info", "baseInfo",FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 10000, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 隐藏字段 竞争对手名称
    COMPETITOR_NAME_HIDE("text_6", "enum.competitorAnalysis.attrName.competitor_name", "competitorName", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9999, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 隐藏字段 客户名称
    CUSTOMER_NAME_HIDE("text_7", "enum.competitorAnalysis.attrName.customer_name", "customerName", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9998, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 隐藏字段 关联机会
    OPPORTUNITY_NAME_HIDE("text_8", "enum.competitorAnalysis.attrName.opportunity_name", "opportunityName", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9997, 0, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //威胁指数
    THREAT_INDEX("num_1", "enum.competitorAnalysis.attrName.threat_index", "threatIndex", FieldTypeEnum.STAR.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9990, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //竞争指标
    COMPETITIVE_INDICATORS("other_2", "enum.competitorAnalysis.attrName.competitive_indicators", "competitiveIndicators",FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9980, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //报价
    QUOTED_PRICE("text_1", "enum.competitorAnalysis.attrName.quoted_price", "quotedPrice", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9970, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //售后服务
    AFTER_SERVICE("text_2", "enum.competitorAnalysis.attrName.after_service", "afterService", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9960, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //产品功能
    PRODUCT_FUNCTION("text_3", "enum.competitorAnalysis.attrName.product_function", "productFunction", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9950, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //产品体验
    PRODUCT_EXPERIENCE("text_4", "enum.competitorAnalysis.attrName.product_experience", "productExperience", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9940, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //客情关系
    CUSTOMER_RELATIONSHIP("text_5", "enum.competitorAnalysis.attrName.customer_relationship", "customerRelationship", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),

    ;
    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;
    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    CompetitorAnalysisEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                   Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }



    /**
     * app端详情默认标签显示字段
     *
     * @return List
     */
    public static List<Object> getLabelAttrList() {
        return Arrays.asList();
    }

    /**
     * 详情默认摘要
     */
    public static List<Object> getSummaryAttrList() {
        return Arrays.asList(THREAT_INDEX);
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    /**
     * 不支持在swot显示
     * date: 2022/8/30 5:15 下午
     * @author yingjf
     */
    public static List<String> getUnSupportSwotAttrList(){
        return Arrays.asList(BASE_INFO.getAttr(),COMPETITOR_NAME_HIDE.getAttr(),CUSTOMER_NAME_HIDE.getAttr(),OPPORTUNITY_NAME_HIDE.getAttr(),THREAT_INDEX.getAttr(),COMPETITIVE_INDICATORS.getAttr());
    }

    /**
     * 根据属性名获取中文名称
     * @param attr
     * @return
     */
    public static String getNameByAttr(String attr){
        String name = null;
        for (CompetitorAnalysisEnum value : values()) {
            if (Objects.equals(value.getAttr(),attr)) {
                name = value.getAttrName();
            }
        }
        return name;
    }

    /**
     * 根据属性列表获取名称列表
     * @param attrList
     * @return
     */
    public static String getNameListByAttrStr(List<String> attrList){
        if (attrList == null){
            return "";
        }
        return attrList.stream().map(item -> getNameByAttr(item)).filter(item -> item != null).collect(Collectors.joining(","));
    }
    /**
     * 不支持在swot显示的字段类型
     * date: 2022/9/15 3:18 下午
     * @author yingjf
     * @param :
     */
    public static List<Integer> getUnSupportSwotFieldType(){
        return Arrays.asList(FieldTypeEnum.TEXT.getType());
    }

    public static CompetitorAnalysisEnum getByAttr(String attr){
        CompetitorAnalysisEnum competitorAnalysisEnum = null;
        for (CompetitorAnalysisEnum value : values()) {
            if (Objects.equals(value.getAttr(),attr)) {
                competitorAnalysisEnum = value;
            }
        }
        return competitorAnalysisEnum;
    }
}
